package com.hezhanying.controller;

import com.hezhanying.pojo.Dept;
import com.hezhanying.pojo.Result;
import com.hezhanying.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result getAllDepts(){
        log.info("获取所有部门信息");
        List<Dept> allDept = deptService.getAllDept();
        return Result.success(allDept);
    }
    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        log.info("添加部门");
        deptService.addDept(dept);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteDept(@PathVariable Integer id){
        log.info("删除部门");
        deptService.deleteDept(id);
        return Result.success();
    }
    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        log.info("修改部门");
        deptService.updateDept(dept);
        return Result.success();
    }
}
